﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TestPictrueGenerator
{
    public class DPI_Timming
    {
        public UInt16 HSW { get; set; }
        public UInt16 HBP { get; set; }
        public UInt16 HACT { get; set; }
        public UInt16 HFP { get; set; }
        public UInt16 VSW { get; set; }
        public UInt16 VBP { get; set; }
        public UInt16 VACT { get; set; }
        public UInt16 VFP { get; set; }

        public DPI_Timming(UInt16 hsw, UInt16 hbp, UInt16 hact, UInt16 hfp, UInt16 vsw, UInt16 vbp, UInt16 vact, UInt16 vfp) 
        {
            this.HSW = hsw;
            this.HBP = hbp;
            this.HACT = hact;
            this.HFP = hfp;
            this.VSW = vsw;
            this.VBP = vbp;
            this.VACT = vact;
            this.VFP = vfp;
        }

        public DPI_Timming()
        {
            HSW = 0;
        }

        public int getClockFromFps(int fps)
        {
            int ret = 0;
            ret = (HSW + HBP + HACT + HFP) * (VSW + VBP + VACT + VFP) * fps;
            return ret;
        }

        public static int getClockFromFps(DPI_Timming tim, int fps)
        {
            int ret = 0;
            ret = (tim.HSW + tim.HBP + tim.HACT + tim.HFP) * (tim.VSW + tim.VBP + tim.VACT + tim.VFP) * fps;
            return ret;
        }

        public static int getFpsFromClock(DPI_Timming tim, int clk)
        {
            int ret = 0;
            ret = clk / ((tim.HSW + tim.HBP + tim.HACT + tim.HFP) * (tim.VSW + tim.VBP + tim.VACT + tim.VFP));
            return ret;
        }
    }

    public class DSI_Timming :DPI_Timming
    {
        UInt16 lane { get; set; }
        UInt16 colorformat { get; set; }
        //DPI_Timming DpiTimming { get; set; }

        public DSI_Timming()
        {

        }

        public DSI_Timming(DPI_Timming dpitm, UInt16 lane, UInt16 colorformat)
        {
            HSW = dpitm.HSW;
            HBP = dpitm.HBP;
            HACT = dpitm.HACT;
            HFP = dpitm.HFP;
            VSW = dpitm.VSW;
            VBP = dpitm.VBP;
            VACT = dpitm.VACT;
            VFP = dpitm.VFP;
            
            this.lane = lane;
            this.colorformat = colorformat;
        }

        public int getBitrate(int fps)
        {
            int ret = 0;

            ret = base.getClockFromFps(fps) * colorformat / lane;

            return ret;
        }
    }
}
